package com.ziyun.erp.web.modules.storeMaterialCheck.controller;

import java.util.Arrays;
import java.util.Map;

import com.ziyun.erp.common.utils.UserUtils;
import com.ziyun.erp.modules.storeMaterialCheck.vo.MaterialCheckVo;
import io.renren.common.validator.ValidatorUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.ziyun.erp.modules.storeMaterialCheck.entity.StoreMaterialCheckEntity;
import com.ziyun.erp.modules.storeMaterialCheck.service.StoreMaterialCheckService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;



/**
 * 门店耗材盘点表
 *
 * @author xueqz
 * @email 
 * @date 2019-01-17 14:40:13
 */
@RestController
@RequestMapping("storeMaterialCheck/storematerialcheck")
public class StoreMaterialCheckController {
    @Autowired
    private StoreMaterialCheckService storeMaterialCheckService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("storeMaterialCheck:storematerialcheck:list")
    public R list(@RequestBody Map<String, Object> params){



        PageUtils page = storeMaterialCheckService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{checkId}")
    @RequiresPermissions("storeMaterialCheck:storematerialcheck:info")
    public R info(@PathVariable("checkId") Integer checkId){
        StoreMaterialCheckEntity storeMaterialCheck = storeMaterialCheckService.selectById(checkId);

        return R.ok().put("storeMaterialCheck", storeMaterialCheck);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("storeMaterialCheck:storematerialcheck:save")
    public R save(@RequestBody StoreMaterialCheckEntity storeMaterialCheck){
        storeMaterialCheckService.insert(storeMaterialCheck);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("storeMaterialCheck:storematerialcheck:update")
    public R update(@RequestBody StoreMaterialCheckEntity storeMaterialCheck){
        ValidatorUtils.validateEntity(storeMaterialCheck);
        storeMaterialCheckService.updateAllColumnById(storeMaterialCheck);//全部更新
        
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("storeMaterialCheck:storematerialcheck:delete")
    public R delete(@RequestBody Integer[] checkIds){
        storeMaterialCheckService.deleteBatchIds(Arrays.asList(checkIds));

        return R.ok();
    }
    /**
     * 信息
     */
    @RequestMapping("/checkInfo/{checkId}")
    public R checkInfo(@PathVariable("checkId") Integer checkId){

        return storeMaterialCheckService.checkInfo(checkId);
    }

    /**
     * 信息
     */
    @RequestMapping("/auditCheck")
    public R auditCheck(@RequestBody MaterialCheckVo materialCheckVo){

        materialCheckVo.setCheckName(UserUtils.getCurentUser().getUsername());
        return storeMaterialCheckService.auditCheck(materialCheckVo);
    }

}
